<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.io.*,java.util.*,java.net.*" %>
<%
//request.setCharacterEncoding("UTF-8");

String pathName = request.getParameter("path");
String filename = request.getParameter("file");

System.out.println("SOURCE 1: " + filename);
//filename = new String(filename.getBytes("8859_1"),"UTF-8");
filename = new String(filename.getBytes("8859_1"),"EUC-KR");
System.out.println("SOURCE 3: " + filename);
File fFile = new File(getServletContext().getRealPath(pathName+"/"+filename)); 


String strClient = request.getHeader("user-agent");

if(fFile.exists())
{
 	if(strClient.indexOf("MSIE 5.5") != -1)
 	{
  		response.setContentType("doesn/matter;"); 
 	}
 	else
 	{
  		response.setContentType("Content-type: application/octet-stream;");
 	}
 	response.setHeader("Content-Disposition","attachment;filename="+filename+";");
 	response.setHeader("Content-Transfer-Encoding","binary;");

 	//-- 2009.02.24 edited by Sam Kim --//response.setHeader("Content-Length",""+fFile.length());
 	int filesize = (int)fFile.length();
 	response.setContentLength( (int)filesize );
	 //
	response.setHeader("Pragma","no-cache;");
 	response.setHeader("Expires","-1;");
 
 	byte b[] = new byte[1024];
 	BufferedInputStream fin = new BufferedInputStream(new FileInputStream(fFile));
 	BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
 
 	try
 	{
  		int read=0;
  		while((read = fin.read(b)) != -1 )
  		{
   			outs.write(b,0,read);
  		}
  		System.out.println("succeed BBa: " + fFile.getPath());
 	}
 	catch(Exception e){
  			out.println(e);
 	}
 	finally
 	{
  		if(outs != null)outs.close();
  		if(fin != null)fin.close();
 	}
}
else {
	//out.println("file not found");
	System.out.println("EU5 file not found : " + fFile.getPath());
}
%>

